﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class Customer_inquiry : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["ID"] != null)
            {             
                BookInfo books = new BookInfo();
                string message = Request.QueryString["ID"];
                int id = Convert.ToInt32(message);
                DataList1.DataSource = books.GetBookNameById(id);
                DataList1.DataBind();
            }
        }
    }
    protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    //往购物车中增加物品
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "add")
        {

            //取出其中的textbox空间的值，为用户购买的数量
            TextBox tb = (TextBox)e.Item.FindControl("TB_num");
            if (tb.Text.ToString() != "")
            {
                int num = Convert.ToInt32(tb.Text.ToString());
                string id = Convert.ToString(e.CommandArgument);
                //先就得检查购物车是否存在,如果不存在,则建立购物车
                if (Session["car"] == null)
                {
                    System.Collections.Hashtable ht = new Hashtable();
                    ht.Add(id, num);
                    Session["car"] = ht;
                }

                //判断所选的物品在购物车中是否存在，
                //如果不存在就将数量置为num,存在的话则增加num

                else
                {
                    Hashtable ht = (Hashtable)Session["car"];
                    if (ht[id] == null)
                    {
                        ht[id] = num;
                    }
                    else
                    {
                        ht[id] = (int)ht[id] + num;
                    }
                    Session["car"] = ht;
                }


            }
        }
    }

    //进入购物车页面
    protected void Button1_Click(object sender, EventArgs e)
    {

        Response.Redirect("~/Member/shoppingCar.aspx");
    }
}



           